/* Node.java
 * Class for a mutable node object
 * Holds an object variable which will actually be a dictionary (array-map in clojure)
 */
package objects;

import clojure.lang.IDeref;

public class Node implements IDeref {

	public Object dict;
	
	public Node(Object dict) {
		this.dict = dict;
	}
	
	public Node() {
		this.dict = null;
	}
	
	@Override
	public Object deref() {
		return this.dict;
	}
	
	public Object setDict(Object dict) {
		this.dict = dict;
		return dict;
	}
	
    public boolean equals(Object other) {
		if (other == null) {
		    return false;
		}
		/* Dicts are the same object?
		 * usually happens if nodes are the same object or if both dicts are null */
		if (this.dict == ((Node) other).dict) {
			return true;
		}
		/* One of the dicts is null? */
		if (this.dict == null || ((Node) other).dict == null) {
			return false;
		}
		/* Dictionary content comparison */
        return (this.dict.equals(((Node) other).dict));
    }
}
